<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="团长名称">
              <a-input placeholder="请输入团长名称" v-model="queryParam.shopName"></a-input>
<!--              <j-input v-model="queryParam.shopName" placeholder="请输入团长名称"></j-input>-->
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="团长电话">
              <a-input placeholder="请输入团长电话" v-model="queryParam.tel"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="地址">
              <a-input placeholder="请输入地址" v-model="queryParam.location"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="状态">
<!--              <j-dict-select-tag placeholder="请选择状态" dictCode="shop_status" v-model="queryParam.status"></j-dict-select-tag>-->
              <a-select  v-model="queryParam.status" placeholder="请选择状态">
                <a-select-option value="">
                  全部
                </a-select-option>
                <a-select-option value="1">
                  已上线
                </a-select-option>
                <a-select-option value="3">
                  已下线
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd(xianlu,routeId)" type="primary" icon="plus">新增团长</a-button>
<!--      <a-button type="primary" icon="download" @click="handleExportXls('路线模块')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
<!--        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>-->
        <a-button type="primary" style="margin-left: 8px" @click="batchDel1"> 批量取消下挂 </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>


      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="status_dictText" slot-scope="text,record">
          <div v-html="text" v-if="record.status==1" style="color: #4D90FE;"></div>
          <div v-html="text" v-else style="color: #ff5500"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="sort" slot-scope="text, record,index">
          <Edittablecell v-if="update" :text="record.sort" @change="onCellChange(index, 'sort', $event)"  />
        </template>
        <span slot="action" slot-scope="text, record">
          <span>
            <a-popconfirm title="确定取消吗?" @confirm="() => handleQuXiao(record.id)">
              <a>取消下挂</a>
            </a-popconfirm>
          </span>
        </span>

      </a-table>
    </div>

    <TuanZhangModal ref="tuanzhangmodal" @ok="modalFormOk" @close="closeMe"></TuanZhangModal>
<!--    <SeeRouteModal ref="seeModalForm" @ok="modalFormOk"></SeeRouteModal>-->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin1'
  import Edittablecell from './Edittablecell.vue'
  import TuanZhangModal from './TuanZhangModal'
  import { deleteAction, putAction } from '@api/manage'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: 'SeeRouteListForm',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      Edittablecell,
      JDictSelectTag,
      JInput,
      TuanZhangModal
    },
    data () {
      return {
        update:true,
        routeId:'',
        xianlu:'',
        description: '线路下团长查看',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'团长名称',
            align:"center",
            dataIndex: 'shopName'
          },
          {
            title:'团长电话',
            align:"center",
            dataIndex: 'tel'
          },
          {
            title:'地址',
            align:"center",
            dataIndex: 'location'
          },
          {
            title:'详细地址',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'团长排序',
            align:"center",
            dataIndex: 'sort',
            width: '100px',
            scopedSlots: { customRender: 'sort' }
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText',
            scopedSlots: { customRender: 'status_dictText' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          // list: "/shop/route/list",
          list:"/shop/routeShop/queryShopList",
          delete: "/shop/route/delete",
          deleteBatch: "/shop/routeShop/deleteBatch",//批量或者单个取消下挂
          exportXlsUrl: "/shop/route/exportXls",
          importExcelUrl: "shop/route/importExcel",
          edit:"/shop/routeShop/edit" //修改团长排序
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //新增团长
      handleAdd(xianlu,id){
        console.log(xianlu)
          this.$refs.tuanzhangmodal.add(xianlu,id);
          this.$refs.tuanzhangmodal.title = "设置线路："+xianlu;
          this.$refs.tuanzhangmodal.disableSubmit = false;
      },
      //单个取消下挂
      handleQuXiao(id){
        this.loading = true;
        let ids = id+','
        deleteAction(this.url.deleteBatch, { ids: ids }).then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            this.loadData();
            this.onClearSelected();
          } else {
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.loading = false;
        });
      },
      edit(record){
        this.queryParam.routeId = record.id
        this.routeId = record.id
        this.loadData()
      },
      searchReset(){
        this.update = false
        console.log(this.routeId)
        this.queryParam = {}
        this.queryParam.routeId = this.routeId

        this.loadData(1);
        this.$nextTick(() => {
          this.update = true
        })
      },
      //改变序号
      onCellChange(key, dataIndex, value) {
        const dataSource = [...this.dataSource];
        dataSource[key][dataIndex] = value;
        this.dataSource = dataSource;
        this.loading = true
        this.update = false
        console.log(dataSource[key].id)
        putAction(this.url.edit,{id:dataSource[key].id,sort:value}).then((res)=>{
          if (res.success) {
            this.$message.success(res.message);



            this.$nextTick(()=>{
                this.searchReset()

            })
          } else {
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.loading = false;
        })




      },
      //批量取消下挂
      batchDel1: function () {
        if (!this.url.deleteBatch) {
          this.$message.error("请设置url.deleteBatch属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          console.log(ids)
          // debugger
          this.$confirm({
            title: "确认取消下挂",
            content: "是否取消选中数据下挂团长?",
            onOk: function () {
              that.loading = true;
              deleteAction(that.url.deleteBatch, { ids: ids }).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },

//关闭窗口刷新
      closeMe(){
        this.searchReset()
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>